package anonymouschat.client.frames;

import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import anonymouschat.client.Identity;
import anonymouschat.utils.LocalFileOps;

/**
 * Log Frame shows chat log with a specific user.
 * 
 * @author hb
 * 
 */
public class LogFrame extends JFrame {
	private static final long serialVersionUID = 1L;
	private static final int WIDTH = 500;
	private static final int HEIGHT = 500;
	private JTextArea msgArea;
	private JScrollPane msgScr;
	private Identity identity;

	/**
	 * Constructor
	 * 
	 * @param dstuserName
	 *            target userName
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	public LogFrame(Identity identity, String dstUserName)
			throws ClassNotFoundException, IOException {
		super();
		this.identity = identity;
		initComponents(dstUserName);
	}

	/**
	 * Initialize components.
	 * 
	 * @param dstUserName
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	private void initComponents(String dstUserName)
			throws ClassNotFoundException, IOException {
		this.msgArea = new JTextArea();
		this.msgArea.setText(LocalFileOps.getChatHist(identity, dstUserName));
		this.msgArea.setEditable(false);
		this.msgScr = new JScrollPane(msgArea);
		this.add(msgScr);
		this.setSize(WIDTH, HEIGHT);
		this.setVisible(true);
	}
}
